<template>
	<view class="">
		<view class="clear top_btn">
			<view class="left" v-for="(item,index) in type" :key="index"  @tap="changeindex(index,item.is_check)">
				<view class="top_btn_text" :class="{'type-active':index==current}">
					{{item.name}}
				</view>
			</view>
		</view>
		
		<view class="list-container">
			<view class="shenhe-list1" v-for="(items,index) in lists" :key="index" @tap="goinfo" :data-id="items.id">
				<view class="clear shenhe-text">
					<text class="left">申请金额 </text>
					<text class="right black_font">{{items.capital}}</text>
				</view>
				<view class="clear shenhe-text">
					<text class="left">客户姓名 </text>
					<text class="right blue_text" style="font-weight: bold;">{{items.username}}</text>
				</view>
				<view class="clear shenhe-text">
					<text class="left">申请时间 </text>
					<text class="right">{{items.addtime}}</text>
				</view>
				<image src="../../static/img/to.png" class="go_icon"></image>
				
			</view>
		</view>
		<image src="../../static/img/nodata.png" class="no-data" v-if="ishas1"  mode="widthFix"></image>
	</view>
</template>

<script>
	import httpPath from '@/static/js/path.js';
	import {getlogin} from '@/static/js/login.js';
	import {timestampToDate} from '@/static/js/login.js';
	import {fmoney} from '@/static/js/login.js';
	
	// import MescrollItem from "./shenhe-item.vue";
	import MescrollUni from "@/components/mescroll-uni/uni-load-more.vue";
	var  _self,
	page = 1;
	export default {
		components: {
		    MescrollUni
		},
		data() {
			return {
				ishas1:false,
				current:0,
				type:[
					{name:"全部",is_check:-1},
					{name:"未审核",is_check:0},
					{name:"已审核",is_check:1},
				],
				lists:[],
			    is_check:-1,
				loadingType: 0,
				contentText: {
				 	contentdown: "上拉显示更多",
				 	contentrefresh: "正在加载...",
				 	contentnomore: "没有更多数据了"
				}
			}
		},
		onShow() {
			this.user = getlogin();
			if(!this.user.islogin){
				uni.showModal({
				   showCancel:false,
				   content:"您还没有登录，请登录"
				})
				uni.navigateTo({
					url:"../public/login"
				})
			}
			page = 1;
			_self = this;
			_self.fnGetData();
		},
		onLoad() {
			this.user = getlogin();
			if(!this.user.islogin){
				uni.showModal({
				   showCancel:false,
				   content:"您还没有登录，请登录"
				})
				uni.navigateTo({
					url:"../public/login"
				})
			}
			page = 1;
			_self = this;
			_self.fnGetData();
		},
		onReachBottom: function() {
			if (_self.loadingType != 0) {//loadingType!=0;直接返回
				return false;
			}
			_self.loadingType = 1;
			uni.showNavigationBarLoading();//显示加载动画
			page++;//每触底一次 page +1
			console.log(page)
			uni.request({
				url: httpPath.filePath+"/api.php/index/user/loan_check_list/",
				method:'POST',
				header:{'content-type':'application/x-www-form-urlencoded'},
				data: {page:page,member_id:this.user.member_id,user_id:this.user.user_id,is_check:this.is_check},
				success: (res) => {
					if (res.data.result.length==0) {//没有数据
						_self.loadingType = 2;
						uni.hideNavigationBarLoading();//关闭加载动画
						return false;
					}
					for (let i = 0;i < res.data.result.length;i++) {
						res.data.result[i].addtime=timestampToDate(res.data.result[i].addtime)
						res.data.result[i].capital=fmoney(res.data.result[i].capital)
						_self.lists.push(res.data.result[i]);
					}
					_self.loadingType = 0;//将loadingType归0重置
					uni.hideNavigationBarLoading();//关闭加载动画
				}
			});
		
		},
		onPullDownRefresh() {
			page=1
			_self.loadingType=0;
		    this.fnGetData();   
		    setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
	       //改变审核状态
		   changeindex(index,is_check){ 
			   
			   this.lists=[];
			   this.current=index;
			   this.is_check=is_check;
			   // console.log(this.current)
			   page = 1;
			   _self = this;
			   _self.loadingType=0;
			   _self.fnGetData();
		   },
		   //点击跳转详情
			goinfo(e){
			   uni.navigateTo({
				url:"../myself/info?id="+e.currentTarget.dataset.id
			   })
			},
		    fnGetData(){
				// console.log(this.is_check)
				uni.request({
					url: httpPath.filePath+"/api.php/index/user/loan_check_list/",
					method:'POST',
					data:{page:page,member_id:this.user.member_id,user_id:this.user.user_id,is_check:this.is_check},
					header:{'content-type':'application/x-www-form-urlencoded'},
					success: res => {
						if(res.data.code == "200"){
							this.lists = res.data.result;
							if(this.lists.length==0){
								this.ishas1=true;
							}else{
								this.ishas1=false;
							}
							for(let i=0;i<res.data.result.length;i++){
								this.lists[i].addtime=timestampToDate(res.data.result[i].addtime)
								this.lists[i].capital=fmoney(res.data.result[i].capital)
							}
						}
					}
				});
		    },
		}
	}
</script>

<style>
	@import "../../colorui/main.css";
	page{background: #fff;}
</style>
